<script>
  let bg = document.getElementById('page-bg');
  bg.style.setProperty('will-change', 'filter', '');
  let hue = 0;

  // Dark mode support
  let isDark = document.documentElement.classList.contains('dark');
  document.addEventListener('hbThemeChange', (e) => {
    console.debug('Theme changed - isDarkTheme? ' + e.detail.isDarkTheme());
    isDark = e.detail.isDarkTheme();
  });

  setInterval(
    function () {
      hue = (hue + 1) % 360.;

      if (isDark) {
        bg.style.setProperty('filter', 'hue-rotate(' + hue + 'deg) invert(1) saturate(2)', '');
      } else {
        bg.style.setProperty('filter', 'hue-rotate(' + hue + 'deg)', '');
      }

    }, (5000 / 360.));
</script>
